<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <div id="btn">开始</div>
  <span id="result">0</span>
  <script>
    var btn=document.getElementById('btn')
    var result=document.getElementById('result')
    /* const timer={
      time:0,
      start:function(){
        var _this=this
        btn.onclick=function(){
          setInterval(function(){
            _this.time++;
            result.innerHTML=_this.time
          },1000)
        }
      }
    }  */
    const timer={
      time:0,
      start:function(){
        btn.onclick=()=>{
          setInterval(()=>{
            this.time++;
            result.innerHTML=this.time
          },1000)
        }
      }
    }
    timer.start()
  </script>
</body>
</html>